package Database;

import java.sql.Connection;
import java.sql.Statement;
import javax.swing.JOptionPane;
import oracle.jdbc.pool.OracleDataSource;

public class CreateAllTabel {

    public static void main(String[] args) {
        String url = "jdbc:oracle:thin:@localhost:1521:XE";
        String name = "hr";
        String pass = "12345";
        Connection con;
        try {
            OracleDataSource ods = new OracleDataSource();
            ods.setURL(url);
            con = ods.getConnection(name, pass);
            Statement stat = con.createStatement();
            String user = "create table USER_PENERIMA(ID_USER varchar2(5)," + "NAMA_USER varchar2(20),"
                    + "constraint USER_PK primary key (ID_USER) enable)";
            stat.executeQuery(user);
            String sekre = "create table USER_SEKRETARIAT(ID_SEKRETARIAT varchar2(5)," + "NAMA_SEKRETARIAT varchar2(20),"
                    + "constraint SEKRETARIAT_PK primary key (ID_SEKRETARIAT) enable)";
            stat.executeQuery(sekre);
////                    + "constraint KELENGKAPAN_PK primary key (ID_SEKRETARIAT) enable,"
//            //                    + "constraint KELENGKAPAN_FK1 foreign key (NIM) references MAHASISWA (NIM)on delete cascade enable,"
////                    + "constraint KELENGKAPAN_FK2 foreign key (ID_SEKRETARIAT) references SEKRETARIAT (ID_SEKRETARIAT)on delete cascade enable)";
//            stat.executeQuery(kel);
            String surat = "create table SURAT(NO_SURAT varchar2(6)," + "PERIHAL varchar2(20)," + "ASAL_SURAT varchar2(20)," + "PENERIMA_SURAT varchar2(20)," + "ID_PENERIMA varchar2(5)," + "LETAK_SURAT varchar2(15)," 
                    + "PETUGAS_PENERIMA varchar2(15)," + "TANGGAL_TERIMA date," + "DAFTAR_TERIMA varchar2(10))";
            stat.executeQuery(surat);
            String dokumen = "create table DOKUMEN(NO_DOKUMEN varchar2(6)," + "PERIHAL varchar2(20)," + "ASAL_DOKUMEN varchar2(20)," + "PENERIMA_DOKUMEN varchar2(20)," + "ID_PENERIMA varchar2(5)," + "LETAK_DOKUMEN varchar2(15)," 
                    + "PETUGAS_PENERIMA varchar2(15)," + "TANGGAL_TERIMA date," + "DAFTAR_TERIMA varchar2(10))";
            stat.executeQuery(dokumen);
            JOptionPane.showMessageDialog(null, "Koneksi OK" + "\nTabel Sukses Dibuat");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Error :" + e.getMessage());
        }
    }
}
